{extend name="property/public/insidePageBase" /}
{block name="title"}绑定能源设备{/block}x
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label required">房间名称</label>
                <div class="layui-input-block">
                    <input type="text"  value="{$info['full_room_name']}" disabled  lay-verify="require" autocomplete="off" placeholder="请输入房间名称" class="layui-input">
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs10" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">设备选择</label>
                        <div class="layui-input-block">
                            <select name="meter_id" lay-filter="meter_id" lay-search>
                                <option value="">请选择</option>
                                {foreach $meterList as $k=>$v}
                                <option value="{$v['id']}" >{$v['energy_name']} 【{$v['energy_no']}
                                    {if $v['energy_type'] == 11} 电表{/if}
                                    {if $v['energy_type'] == 12} 冷水表{/if}
                                    {if $v['energy_type'] == 13} 热水表{/if}
                                    {if $v['energy_type'] == 14} 燃气表{/if}】
                                </option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2" >
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-fluid addEnergyMeter"> 添加新设备 </button>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注说明</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入备注说明" class="layui-textarea" name="remark"></textarea>
                </div>
            </div>

            <div class="layui-form-item layui-hide">
                <button class="layui-btn" lay-submit lay-filter="submitBtn" id="submitBtn">提交</button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form'], function () {
        var form = layui.form;
        $('.addEnergyMeter').on('click', function() {
            var url = '{:url("propertyEnergyMeterAdd")}';
            var index = parent.layer.open({title: '添加',type: 2,shade: 0.2, maxmin:true,area: ['800px', '500px'], content: url, btnAlign: 'c' , btn: ['确定', '取消'] , yes: function (index, layero) {
                    var iframeWindow = parent.window['layui-layer-iframe' + index] , submit = layero.find('iframe').contents().find("#submitBtn");
                    iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                        var field = data.field; //获取提交的字段
                        var loadAdd = parent.layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, field, function (res) {
                            parent.layer.close(loadAdd);
                            if (res.code === 0) {
                                table.reload(index); //数据刷新
                                parent.layer.close(index); //关闭弹层
                                parent.layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                parent.layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        });
    });
</script>
{/block}